package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.GoodsPackage;
import com.ruoyi.service.IGoodsPackageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售促销套餐Controller
 * 
 * @author ruoyi
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/webshop/GoodsPackage")
public class GoodsPackageController extends BaseController
{
    @Autowired
    private IGoodsPackageService goodsPackageService;

    /**
     * 查询销售促销套餐列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPackage:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll()
    {
        startPage();
        List<GoodsPackage> list = goodsPackageService.selectGoodsPackageListAll();
        return success(list);
    }
    /**
     * 查询销售促销套餐列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPackage:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsPackage goodsPackage)
    {
        startPage();
        List<GoodsPackage> list = goodsPackageService.selectGoodsPackageList(goodsPackage);
        return getDataTable(list);
    }

    /**
     * 导出销售促销套餐列表
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPackage:export')")
    @Log(title = "销售促销套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GoodsPackage goodsPackage)
    {
        List<GoodsPackage> list = goodsPackageService.selectGoodsPackageList(goodsPackage);
        ExcelUtil<GoodsPackage> util = new ExcelUtil<GoodsPackage>(GoodsPackage.class);
        util.exportExcel(response, list, "销售促销套餐数据");
    }

    /**
     * 获取销售促销套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPackage:query')")
    @GetMapping(value = "/{packageId}")
    public AjaxResult getInfo(@PathVariable("packageId") Long packageId)
    {
        return success(goodsPackageService.selectGoodsPackageByPackageId(packageId));
    }

    /**
     * 新增销售促销套餐
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPackage:add')")
    @Log(title = "销售促销套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsPackage goodsPackage)
    {
        return toAjax(goodsPackageService.insertGoodsPackage(goodsPackage));
    }

    /**
     * 修改销售促销套餐
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPackage:edit')")
    @Log(title = "销售促销套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsPackage goodsPackage)
    {
        return toAjax(goodsPackageService.updateGoodsPackage(goodsPackage));
    }

    /**
     * 删除销售促销套餐
     */
    @PreAuthorize("@ss.hasPermi('webshop:GoodsPackage:remove')")
    @Log(title = "销售促销套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{packageIds}")
    public AjaxResult remove(@PathVariable Long[] packageIds)
    {
        return toAjax(goodsPackageService.deleteGoodsPackageByPackageIds(packageIds));
    }
}
